﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Harkon.AppServer.cOne.Service;
using Harkon.AppServer.cOne.CommandQueues;
using System.Threading;
using SampleQueueComponent;

namespace SampleQueueUser
{
    public class TimedInsertion : AbstractService, ITimedInsertion
    {
        public ICommandQueueManager QueueManager { get; set; }

        Thread t;

        public override bool Init()
        {
            if (base.Init())
            {
                t = new Thread(Run);
                t.IsBackground = true;
                return true;
            }
            return false;
        }

        public override bool Start()
        {
            if (base.Start())
            {
                t.Start();
                return true;
            }
            return false;
        }

        private void Run()
        {
            Thread.Sleep(2000);
            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "FirstTest" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "2nd" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "3rd" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "4th" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "5th" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "6th" });

            QueueManager.EnqueueCommand(new SampleQueueCommand { CommandName = "7th" });

        }
    }
}
